home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dc1 / subs.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  17KB  |  930 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. /*
  7. **      $Filename: subs.c $
  8. **      $Author: dice $
  9. **      $Revision: 30.326 $
  10. **      $Date: 1995/12/24 06:09:48 $
  11. **      $Log: subs.c,v $
  12.  * Revision 30.326  1995/12/24  06:09:48  dice
  13.  * .
  14.  *
  15.  * Revision 30.325  1995/12/24  05:38:15  dice
  16.  * .
  17.  *
  18.  * Revision 30.5  1994/06/13  18:37:39  dice
  19.  * fixed bug in internationalization where fi is garbage on open failure
  20.  *
  21.  * Revision 30.0  1994/06/10  18:04:57  dice
  22.  * .
  23.  *
  24.  * Revision 1.4  1993/11/14  17:21:14  jtoebes
  25.  * Minor cleanup, delete old code, optimize performance for memory allocations.
  26.  * Improve output for type to string conversion.
  27.  *
  28.  * Revision 1.4  1993/11/14  17:21:14  jtoebes
  29.  * Minor cleanup, delete old code, optimize performance for memory allocations.
  30.  * Improve output for type to string conversion.
  31.  *
  32.  *
  33. **/
  34.  
  35. #include "defs.h"
  36.  
  37. static long **TBase;
  38. static char Buf1[256];
  39.  
  40. Prototype long Align(long, long);
  41. Prototype long PowerOfTwo(ulong);
  42. Prototype void *zalloc(long);
  43. Prototype void *talloc(long);
  44. Prototype void tclear(void);
  45. Prototype void *zrealloc(void *, long, long, long);
  46. Prototype char *SymToString(Symbol *);
  47. Prototype char *TypeToString(Type *);
  48. Prototype char *TypeToProtoStr(Type *, short);
  49. Prototype void eprintf(short, const char *, ...);
  50. Prototype void veprintf(short, const char *, va_list);
  51. Prototype void AddAuxSub(char *);
  52. Prototype void DumpAuxSubs(void);
  53. #ifdef NOTDEF
  54. Prototype void MarkAreaMunged(long, long);
  55. Prototype int  OffsetMunged(long);
  56. #endif
  57.  
  58. Prototype long FPStrToInt(Exp *, char *, int);
  59. Prototype char *IntToFPStr(long, long, long *);
  60. Prototype int FltIsZero(Exp *, char *, int);
  61. Prototype int FltIsNegative(char *, int);
  62. Prototype long FPrefix(Exp *, char *, int, char *);
  63. Prototype void StorToTmpFlt(Exp *, Stor *, TmpFlt *);
  64. Prototype void TmpFltToStor(Exp *, TmpFlt *, Stor *);
  65. Prototype void BalanceTmpFlt(TmpFlt *, TmpFlt *);
  66. Prototype void NormalizeTmpFlt(TmpFlt *);
  67. Prototype int  TmpFltMantDiv(uword *, short, uword);
  68. Prototype int  TmpFltMantMul(uword *, short, uword);
  69.  
  70. Prototype long Internationalize(char *str, long size);
  71. Prototype int LoadLocaleDefs(char *file);
  72.  
  73. Prototype void NoMem(void);
  74.  
  75. long
  76. Align(long bytes, long align)
  77. {
  78.     long n = align - (bytes & (align - 1));
  79.     if (n != align)
  80.     bytes += n;
  81.     return(bytes);
  82. }
  83.  
  84. long
  85. PowerOfTwo(v)
  86. ulong v;
  87. {
  88.     short i;
  89.  
  90.     for (i = 0; v; ++i) {
  91.     if (v & 1) {
  92.         if (v == 1)
  93.         return((int)i);
  94.         return(-1);
  95.     }
  96.     v >>= 1;
  97.     }
  98.     return(-1);
  99. }
  100.  
  101. void *
  102. zalloc(bytes)
  103. long bytes;
  104. {
  105.     static char *Buf;
  106.     static long Bytes;
  107.  
  108.     ++ZAllocs;
  109.  
  110.     bytes = (bytes + 3) & ~3;
  111.  
  112.     if (bytes <= 128)
  113.     {
  114.         if (bytes <= Bytes)
  115.         {
  116.             void *ptr = (void *)Buf;
  117.             Buf += bytes;
  118.             Bytes -= bytes;
  119.             return(ptr);
  120.         }
  121.         else
  122.         {
  123.             void *ptr = malloc(CHUNKSIZE);
  124.  
  125.             ++ZChunks;
  126.  
  127.             if (!ptr)
  128.                 NoMem();
  129.  
  130.             setmem((char *)ptr, CHUNKSIZE, 0);
  131.             Buf = (char *)ptr + bytes;
  132.             Bytes = CHUNKSIZE - bytes;
  133.             return(ptr);
  134.         }
  135.     }
  136.     else /* bytes > 128 */
  137.     {
  138.     void *ptr = malloc(bytes);
  139.     if (!ptr)
  140.         NoMem();
  141.     setmem((char *)ptr, bytes, 0);
  142.     ++ZAloneChunks;
  143.     return(ptr);
  144.     }
  145. }
  146.  
  147. static char *TBuf;
  148. static char *TPtr;
  149. static long TBytes;
  150.  
  151. void *
  152. talloc(bytes)
  153. long bytes;
  154. {
  155.     ++TAllocs;
  156.  
  157.     bytes = (bytes + 3) & ~3;
  158.  
  159.     if (bytes <= 128)
  160.     {
  161.         if (bytes <= TBytes)
  162.         {
  163.             void *ptr = (void *)TPtr;
  164.             TPtr += bytes;
  165.             TBytes -= bytes;
  166.             return(ptr);
  167.         }
  168.         else
  169.         {
  170.             void *ptr = malloc(CHUNKSIZE+sizeof(long)*2);
  171.  
  172.             if (!ptr)
  173.                 NoMem();
  174.  
  175.             if (TBuf) {
  176.                 *(long **)TBuf = (long *)TBase;
  177.                 TBase = (long **)TBuf;
  178.             }
  179.             TBuf = ptr;
  180.             ptr = (long *)ptr + 1;
  181.             *(long *)ptr = CHUNKSIZE;
  182.             ptr = (long *)ptr + 1;
  183.  
  184.             ++TChunks;
  185.             setmem((char *)ptr, CHUNKSIZE, 0);
  186.             TPtr = (char *)ptr + bytes;
  187.             TBytes = CHUNKSIZE - bytes;
  188.             return(ptr);
  189.         }
  190.     }
  191.     else /* bytes > 128 */
  192.     {
  193.     void *ptr = malloc(bytes+sizeof(long)*2);
  194.  
  195.     if (!ptr)
  196.         NoMem();
  197.  
  198.     *(long **)ptr = (long *)TBase;
  199.     TBase = (long **)ptr;
  200.     ptr = (long *)ptr + 1;
  201.     *(long *)ptr = bytes;
  202.     ptr = (long *)ptr + 1;
  203.  
  204.     ++TAloneChunks;
  205.     setmem((char *)ptr, bytes, 0);
  206.     return(ptr);
  207.     }
  208. }
  209.  
  210. void
  211. tclear()
  212. {
  213.     long *ptr;
  214.  
  215.     /*TBytes = 0;*/
  216.     while ((ptr = (long *)TBase) != NULL) {
  217.     TBase = (long **)ptr[0];
  218.     /*setmem((char *)(ptr + 2), ptr[1], 0x81);*/
  219.     free(ptr);
  220.     }
  221. }
  222.  
  223. void *
  224. zrealloc(ptr, objsize, oldsize, newsize)
  225. void *ptr;
  226. long objsize;
  227. long oldsize;
  228. long newsize;
  229. {
  230.     void *new;
  231.  
  232.     if (oldsize > newsize)
  233.     return(ptr);
  234.     new = zalloc(newsize * objsize);
  235.     if (oldsize)
  236.     movmem((char *)ptr, (char *)new, oldsize * objsize);
  237.     /*
  238.     if (ptr) zfree(ptr);
  239.      */
  240.     return(new);
  241. }
  242.  
  243. char *
  244. SymToString(sym)
  245. Symbol *sym;
  246. {
  247.     static char *Buf;
  248.     static long Len;
  249.  
  250.     if (sym == NULL)
  251.     return("<unnamed>");
  252.     if (sym->Len + 1 > Len) {
  253.     if (Buf)
  254.         free(Buf);
  255.     Buf = malloc(sym->Len + 16);
  256.     Len = sym->Len + 16;
  257.     if (!Buf)
  258.         NoMem();
  259.     }
  260.     movmem(sym->Name, Buf, sym->Len);
  261.     Buf[sym->Len] = 0;
  262.     return(Buf);
  263. }
  264.  
  265.  
  266. /*
  267.  *  TypeToProtoStr(type)
  268.  *
  269.  *  Used for -mRRY option
  270.  */
  271.  
  272. char *
  273. TypeToProtoStr(Type *type, short i)
  274. {
  275.     char *ptr = Buf1;
  276.  
  277.     switch(type->Id) {
  278.     case TID_INT:
  279.     if (type->Flags & TF_UNSIGNED)
  280.         i += sprintf(ptr + i, "unsigned ");
  281.     if (type->Flags & TF_SIGNED)
  282.         i += sprintf(ptr + i, "signed ");
  283.     if (type->Flags & TF_CONST)
  284.         i += sprintf(ptr + i, "const ");
  285.     if (type->Flags & TF_VOLATILE)
  286.         i += sprintf(ptr + i, "volatile ");
  287.     i += sprintf(ptr + i,
  288.         (type->Size == 0) ? "void" :
  289.         (type->Size == 1) ? "char" :
  290.         (type->Size == 2) ? "short" :
  291.         (type->Size == 4) ? "long" : "iunknown"
  292.     );
  293.     break;
  294.     case TID_FLT:
  295.     i += sprintf(ptr + i,
  296.         (type->Size == 4) ? "float" :
  297.         (type->Size == 8) ? "double" :
  298.         (type->Size == 16) ? "long double" : "funknown"
  299.     );
  300.     break;
  301.     case TID_PTR:
  302.     case TID_ARY:
  303.     TypeToProtoStr(type->SubType, i);
  304.     i = strlen(ptr);
  305.     i += sprintf(ptr + i, " *");
  306.     break;
  307.     case TID_PROC:
  308.     i += sprintf(ptr + i, "void");
  309.     break;
  310.     case TID_STRUCT:
  311.     i += sprintf(ptr + i, "struct");
  312.     case TID_UNION:
  313.     if (type->Id == TID_UNION)
  314.         i += sprintf(ptr + i, "union");
  315.  
  316.     /*
  317.      *  find associated struct/union name
  318.      */
  319.  
  320.     {
  321.         Symbol *sym;
  322.  
  323.         if ((sym = FindStructUnionTag(type)) != NULL) {
  324.         i += sprintf(ptr + i, " %s", SymToString(sym));
  325.         } else {
  326.         i += sprintf(ptr + i, " unknown ");
  327.         }
  328.     }
  329.     break;
  330.     default:
  331.     i += sprintf(ptr + i, "badid%d", type->Id);
  332.     break;
  333.     }
  334.     return(ptr);
  335. }
  336.  
  337. void
  338. veprintf(short asout, const char *str, va_list va)
  339. {
  340.     if (asout) {
  341.     printf(";");
  342.     vprintf(str, va);
  343.     }
  344.     vfprintf(stderr, str, va);
  345.     if (ErrorFi)
  346.     vfprintf(ErrorFi, str, va);
  347. }
  348.  
  349. void
  350. eprintf(short asout, const char *str, ...)
  351. {
  352.     va_list va;
  353.  
  354.     va_start(va, str);
  355.     veprintf(asout, str, va);
  356.     va_end(va);
  357. }
  358.  
  359. /*
  360.  *
  361.  */
  362.  
  363. typedef struct NameNode {
  364.     struct NameNode *Next;
  365.     char *ASName;
  366. } NameNode;
  367.  
  368. NameNode *ASBase;
  369.  
  370. void
  371. AddAuxSub(name)
  372. char *name;
  373. {
  374.     NameNode *nn;
  375.  
  376.     for (nn = ASBase; nn; nn = nn->Next) {
  377.     if (strcmp(name, nn->ASName) == 0)
  378.         return;
  379.     }
  380.     nn = AllocStructure(NameNode);
  381.     nn->ASName = name;
  382.     nn->Next = ASBase;
  383.     ASBase = nn;
  384. }
  385.  
  386. void
  387. DumpAuxSubs()
  388. {
  389.     NameNode *nn;
  390.  
  391.     for (nn = ASBase; nn; nn = nn->Next)
  392.     printf("\txref\t__%s\n", nn->ASName);
  393. }
  394.  
  395. /*
  396.  *  [+/-]nnn.nnnE[+/-]nnn
  397.  *
  398.  *  Convert FP value to integer.  Generate prefix and exponent
  399.  */
  400.  
  401. long
  402. FPStrToInt(exp, ptr, len)
  403. Exp *exp;
  404. char *ptr;
  405. int len;
  406. {
  407.     char *bp = Buf1;
  408.     long x = FPrefix(exp, ptr, len, bp); /*  convert to prefix and exponent */
  409.     long v;
  410.  
  411.     if (x <= 0)         /*    too small   */
  412.     return(0);
  413.     if (x > sizeof(Buf1))   /*    too large   */
  414.     yerror(exp->ex_LexIdx, EFATAL_FPINT_TOO_LARGE);
  415.  
  416.     ++bp;            /*    skip sign   */
  417.     while (*bp && x) {        /*    skip to actual decimal pt   */
  418.     ++bp;
  419.     --x;
  420.     }
  421.     while (x) {         /*    zero extend to actual dec pt*/
  422.     *bp++ = '0';
  423.     --x;
  424.     }
  425.     *bp = 0;
  426.     v = atol(Buf1+1);
  427.     if (Buf1[0] != 1)
  428.     v = -v;
  429.  
  430.     return(v);
  431. }
  432.  
  433. char *
  434. IntToFPStr(v, isuns, plen)
  435. long v;
  436. long isuns;
  437. long *plen;
  438. {
  439.     if (isuns)
  440.     sprintf(Buf1, "%lu", v);
  441.     else
  442.     sprintf(Buf1, "%ld", v);
  443.     *plen = strlen(Buf1);
  444.     return(strdup(Buf1));
  445. }
  446.  
  447. int
  448. FltIsZero(exp, ptr, len)
  449. Exp *exp;
  450. char *ptr;
  451. int len;
  452. {
  453.     char *bp = Buf1;
  454.  
  455.     (void)FPrefix(exp, ptr, len, bp); /*  convert to prefix and exponent */
  456.  
  457.     ++bp;    /* skip sign   */
  458.     while (*bp) {
  459.     if (*bp != '0')
  460.         return(0);
  461.     ++bp;
  462.     }
  463.     return(1);
  464. }
  465.  
  466. int
  467. FltIsNegative(ptr, len)
  468. char *ptr;
  469. int len;
  470. {
  471.     if (len && *ptr == '-')
  472.     return(1);
  473.     return(0);
  474. }
  475.  
  476. /*
  477.  *  Convert an ascii fp representation to prefix form
  478.  *
  479.  *    [.]nnnnnnnnnnnnnnnnnnnnnnn and exponent
  480.  */
  481.  
  482.  
  483. long
  484. FPrefix(exp, ptr, len, buf)
  485. Exp *exp;
  486. char *ptr;
  487. char *buf;
  488. int len;
  489. {
  490.     long x = 0;         /*    exponent of .prefix */
  491.     short sgn = 1;        /*    sign of prefix    */
  492.     short zero= 1;
  493.     short blen = sizeof(Buf1) - 1;
  494.  
  495.     if (len && *ptr == '+') {
  496.     ++ptr;
  497.     --len;
  498.     }
  499.     if (len && *ptr == '-') {
  500.     ++ptr;
  501.     --len;
  502.     sgn = -1;
  503.     }
  504.  
  505.     *buf++ = sgn;    /*  first element is sign 1 = positive    */
  506.     --blen;
  507.  
  508.     while (len && blen && *ptr >= '0' && *ptr <= '9') {
  509.     if (zero && *ptr == '0') {
  510.         ;
  511.     } else {
  512.         zero = 0;
  513.         *buf++ = *ptr;
  514.         --blen;
  515.         ++x;
  516.     }
  517.     ++ptr;
  518.     --len;
  519.     }
  520.     if (len && *ptr == '.') {
  521.     ++ptr;
  522.     --len;
  523.  
  524.     while (len && blen && *ptr >= '0' && *ptr <= '9') {
  525.         if (zero && *ptr == '0') {
  526.         --x;
  527.         } else {
  528.         zero = 0;
  529.         *buf++ = *ptr;
  530.         --blen;
  531.         }
  532.         ++ptr;
  533.         --len;
  534.     }
  535.     }
  536.     if (blen == 0)
  537.     yerror(exp->ex_LexIdx, EFATAL_FPSTR_TOO_LONG);
  538.     *buf = 0;
  539.  
  540.     if (len && (*ptr == 'e' || *ptr == 'E')) {
  541.     long n = 0;
  542.     short nsgn = 1;
  543.     ++ptr;
  544.     --len;
  545.  
  546.     if (len && *ptr == '-') {
  547.         nsgn = -1;
  548.         ++ptr;
  549.         --len;
  550.     }
  551.     if (len && *ptr == '+') {
  552.         ++ptr;
  553.         --len;
  554.     }
  555.     while (len) {
  556.         n = n * 10 + *ptr - '0';
  557.         ++ptr;
  558.         --len;
  559.     }
  560.     if (nsgn < 0)
  561.         x -= n;
  562.     else
  563.         x += n;
  564.     }
  565.     return(x);
  566. }
  567.  
  568. /*
  569.  *  Convert ascii fp number into a temporary floating point binary
  570.  *  representation.
  571.  */
  572.  
  573. void
  574. StorToTmpFlt(exp, s, f)
  575. Exp *exp;
  576. Stor *s;
  577. TmpFlt *f;
  578. {
  579.     char *bp = Buf1;
  580.  
  581.     /*
  582.      *    bp[0] == -1 if negative, else positive. bp[1..\0] holds digits (ascii)
  583.      *    x is exponent
  584.      */
  585.  
  586.     f->tf_Exponent = FPrefix(exp, s->st_FltConst, s->st_FltLen, bp);
  587.     f->tf_Negative = (bp[0] == -1) ? 1 : 0;
  588.     {
  589.     long z = 0;
  590.     f->tf_LMantissa[0] = z;
  591.     f->tf_LMantissa[1] = z;
  592.     f->tf_LMantissa[2] = z;
  593.     f->tf_LMantissa[3] = z;
  594.     }
  595.  
  596.     ++bp;
  597.     while (*bp) {
  598.     long n = *bp - '0';
  599.     if (f->tf_LMantissa[0] > (ulong)0xFFFFFFFF / 10 - 10)
  600.         break;
  601.     TmpFltMantMul(f->tf_WMantissa, 8, 10);
  602.     --f->tf_Exponent;
  603.     f->tf_LMantissa[3] += n;
  604.     if (f->tf_LMantissa[3] < n) {
  605.         if (++f->tf_LMantissa[2] == 0) {
  606.         if (++f->tf_LMantissa[1] == 0)
  607.             ++f->tf_LMantissa[0];
  608.         }
  609.     }
  610.     ++bp;
  611.     }
  612.  
  613.     /*
  614.      *    normalize
  615.      */
  616.  
  617.     NormalizeTmpFlt(f);
  618. }
  619.  
  620. /*
  621.  *  Convert a TmpFlt back to a storage structure
  622.  *
  623.  *  Construct ascii rep in Buf1
  624.  */
  625.  
  626. void
  627. TmpFltToStor(exp, f, s)
  628. Exp *exp;
  629. TmpFlt *f;
  630. Stor *s;
  631. {
  632.     char *bp = Buf1 + sizeof(Buf1) - 16;
  633.     short i;
  634.  
  635.     sprintf(bp, "E%ld", f->tf_Exponent);
  636.  
  637.     for (i = 0; i < 40; ++i) {        /*    cvt to 40 digit value    */
  638.     *--bp = TmpFltMantDiv(f->tf_WMantissa, 8, 10) + '0';
  639.     }
  640.     if (f->tf_Negative)
  641.     *--bp = '-';
  642.  
  643.     dbprintf(("result = %s\n", bp));
  644.     {
  645.     short len = strlen(bp);
  646.     s->st_FltConst = zalloc(len + 1);
  647.     s->st_FltLen   = len;
  648.     strcpy(s->st_FltConst, bp);
  649.     }
  650. }
  651.  
  652. /*
  653.  *  Balance two fp numbers so exponents match (used add/sub)
  654.  */
  655.  
  656. void
  657. BalanceTmpFlt(f1, f2)
  658. TmpFlt *f1;
  659. TmpFlt *f2;
  660. {
  661.     if ((f1->tf_LMantissa[0] | f1->tf_LMantissa[1] | f1->tf_LMantissa[2] | f1->tf_LMantissa[3]) == 0) {
  662.     f1->tf_Exponent = f2->tf_Exponent;
  663.     return;
  664.     }
  665.     if ((f2->tf_LMantissa[0] | f2->tf_LMantissa[1] | f2->tf_LMantissa[2] | f2->tf_LMantissa[3]) == 0) {
  666.     f2->tf_Exponent = f1->tf_Exponent;
  667.     return;
  668.     }
  669.     if (f1->tf_Exponent < f2->tf_Exponent - 40) {
  670.     long z = 0;
  671.     f1->tf_Exponent = f2->tf_Exponent;
  672.     f1->tf_LMantissa[0] = z;
  673.     f1->tf_LMantissa[1] = z;
  674.     f1->tf_LMantissa[2] = z;
  675.     f1->tf_LMantissa[3] = z;
  676.     return;
  677.     }
  678.     if (f2->tf_Exponent < f1->tf_Exponent - 40) {
  679.     long z = 0;
  680.     f2->tf_Exponent = f1->tf_Exponent;
  681.     f2->tf_LMantissa[0] = z;
  682.     f2->tf_LMantissa[1] = z;
  683.     f2->tf_LMantissa[2] = z;
  684.     f2->tf_LMantissa[3] = z;
  685.     return;
  686.     }
  687.  
  688.     while (f1->tf_Exponent < f2->tf_Exponent) {   /*  10E1, 10E2 -> 1E2, 10E2  */
  689.     TmpFltMantDiv(f1->tf_WMantissa, 8, 10);
  690.     ++f1->tf_Exponent;
  691.     }
  692.     while (f1->tf_Exponent > f2->tf_Exponent) {
  693.     TmpFltMantDiv(f2->tf_WMantissa, 8, 10);
  694.     ++f2->tf_Exponent;
  695.     }
  696. }
  697.  
  698. void
  699. NormalizeTmpFlt(f)
  700. TmpFlt *f;
  701. {
  702.     if ((f->tf_LMantissa[0] | f->tf_LMantissa[1] | f->tf_LMantissa[2] | f->tf_LMantissa[3]) == 0) {
  703.     f->tf_Exponent = 0;
  704.     f->tf_Negative = 0;
  705.     return;
  706.     }
  707.     while (f->tf_LMantissa[0] < 0x7FFFFFFF / 10) {
  708.     TmpFltMantMul(f->tf_WMantissa, 8, 10);
  709.     --f->tf_Exponent;
  710.     }
  711. }
  712.  
  713. int
  714. TmpFltMantDiv(uword *wp, short n, uword v)
  715. {
  716.     short i;
  717.     ulong c;
  718.     ulong r = 0;
  719.  
  720.     for (i = 0; i < n; ++i) {
  721.     r <<= 16;
  722.     c = (wp[i] + r) / v;
  723.     r = (wp[i] + r) % v;
  724.     wp[i] = c;
  725.     }
  726.     return(r);
  727. }
  728.  
  729. int
  730. TmpFltMantMul(uword *wp, short n, uword v)
  731. {
  732.     short i;
  733.     ulong c = 0;
  734.  
  735.     for (i = n - 1; i >= 0; --i) {
  736.     c += wp[i] * v;
  737.     wp[i] = c;
  738.     c >>= 16;
  739.     }
  740.     return(c);
  741. }
  742.  
  743. void
  744. NoMem()
  745. {
  746.     eprintf(0, "NO MEMORY!\n");
  747.     ExitError(25);
  748.     /*zerror(EFATAL_NO_MEMORY);*/
  749. }
  750.  
  751. #ifdef NOTDEF
  752.  
  753. /*
  754.  *  Munged area routines for error tracking
  755.  */
  756.  
  757. typedef struct MunNode {
  758.     struct MunNode *mn_Next;
  759.     struct MunNode *mn_Prev;
  760.     long    mn_OffBeg;
  761.     long    mn_OffEnd;
  762. } MunNode;
  763.  
  764. MunNode *MunBase;
  765. MunNode **MunTail = &MunBase;
  766.  
  767. void
  768. MarkAreaMunged(s, e)
  769. long s, e;
  770. {
  771.     MunNode *mn = zalloc(sizeof(MunNode));
  772.  
  773.     mn->mn_Next = NULL;
  774.     if (MunTail != &MunBase)
  775.     mn->mn_Prev = (MunNode *)MunTail;
  776.     mn->mn_OffBeg = s;
  777.     mn->mn_OffEnd = e;
  778.     *MunTail = mn;
  779.     MunTail = &mn->mn_Next;
  780. }
  781.  
  782. int
  783. OffsetMunged(i)
  784. long i;
  785. {
  786.     static MunNode *MunCache;
  787.     MunNode *mn;
  788.  
  789.     for (mn = MunCache; mn && i < mn->mn_OffBeg; mn = mn->mn_Prev) {
  790.     ;
  791.     }
  792.  
  793.     if (mn == NULL)
  794.     mn = MunBase;
  795.  
  796.     while (mn && i >= mn->mn_OffEnd)
  797.     mn = mn->mn_Next;
  798.  
  799.     MunCache = mn;
  800.  
  801.     if (mn && (i >= mn->mn_OffBeg && i < mn->mn_OffEnd))
  802.     return(1);
  803.     return(0);
  804. }
  805.  
  806. #endif
  807.  
  808. #ifdef LATTICE
  809.  
  810. int
  811. cmpmem(ubyte *s1, ubyte *s2, long n)
  812. {
  813.     while (n) {
  814.     if (*s1 < *s2)
  815.         return(-1);
  816.     if (*s1 > *s2)
  817.         return(1);
  818.     --n;
  819.     ++s1;
  820.     ++s2;
  821.     }
  822.     return(0);
  823. }
  824.  
  825. #endif
  826.  
  827. #ifdef COMMERCIAL
  828.  
  829. typedef struct INatNode {
  830.     struct INatNode *in_Next;
  831.     long    in_Id;
  832.     short    in_Len;
  833.     char    in_Str[4];
  834. } INatNode;
  835.  
  836. INatNode *InBase;
  837.  
  838. /*
  839.  * Looks up a string in the preloaded catalog.  The string must match exactly.
  840.  * The <size> argument includes a terminating \0.
  841.  */
  842.  
  843. long
  844. Internationalize(char *str, long size)
  845. {
  846.     long iidx;
  847.     INatNode *in;
  848.  
  849.     if (str[size-1] == 0)
  850.     --size;
  851.  
  852.     if (str[0]) {
  853.     /* fprintf(stderr, "string %s\n", str); */
  854.     for (iidx = 0, in = InBase; in; in = in->in_Next, ++iidx) {
  855.         /* fprintf(
  856.         stderr, "sizes: %d %d %s\n", size, in->in_Len, in->in_Str); */
  857.         if (size == in->in_Len && strcmp(str, in->in_Str) == 0)
  858.         return(in->in_Id);
  859.     }
  860.     }
  861.     return(-1);
  862. }
  863.  
  864. /*
  865.  * Internationalization file used to convert strings into indexes.  The file
  866.  * contains lines of the form:
  867.  *
  868.  * n:String
  869.  *
  870.  * For example:  '4:This is a test'.  Any line not beginning with a number
  871.  * is ignored.  Numbers containing initial 0's, as in: '0004:This is a test'
  872.  * will be properly interpreted in base 10.  The maximum string length is 4K.
  873.  * ';' or '#' are the accepted comment characters
  874.  */
  875.  
  876. int
  877. LoadLocaleDefs(char *file)
  878. {
  879.     FILE *fi = NULL;
  880.     int r = 0;
  881.     char *ptr;
  882.     char *buf = malloc(4096);
  883.  
  884.     if (buf && (fi = fopen(file, "r"))) {
  885.         INatNode **pin = &InBase;
  886.         INatNode *in;
  887.  
  888.     r = 1;
  889.     while (fgets(buf, 4096, fi)) {
  890.         long id = strtol(buf, &ptr, 10);
  891.         short len;
  892.  
  893.         if (*ptr != ':')    /* ignore improperly formatted lines */
  894.         continue;
  895.         ++ptr;
  896.         len = strlen(ptr);
  897.         if (len && ptr[len-1] == '\n')
  898.         --len;
  899.         ptr[len] = 0;
  900.  
  901.         /* note: space for terminating \0 already handled by in_Str field
  902.          * in structure
  903.          */
  904.  
  905.         in = zalloc(sizeof(INatNode) + len);
  906.         in->in_Len = len;
  907.         in->in_Id = id;
  908.         strcpy(in->in_Str, ptr);
  909.         /* fprintf(
  910.         stderr,
  911.         "ADD %d %d '%s'\n", in->in_Len,in->in_Id, in->in_Str); */
  912.         *pin = in;
  913.         pin = &in->in_Next;
  914.     }
  915.     }
  916.     if (fi)
  917.     fclose(fi);
  918.     if (buf)
  919.     free(buf);
  920.     return(r);
  921. }
  922.  
  923. #endif
  924.  
  925. void
  926. filler_subs_c(void)
  927. {
  928.     Assert(1);
  929. }
  930.